import bcrypt from 'bcrypt';
import { Schema } from 'mongoose';

export default new Schema({
  username: {
    type: String,
    unique: true
  },
  password: {
    type: String,
    //每个字段都具有的setter函数
    set(val: string) {
      //参数2为salt的加密次数
      return bcrypt.hashSync(val, 10);
    }
  },
  is_admin: {
    type: Boolean,
    default: false
  },
  level: {
    type: Number,
    default: 1
  },
  createAt: {
    type: Date,
    default: Date.now
  }
});
